import 'package:flutter/material.dart';
import 'package:x3_base_core/x3_base_core.dart';
import 'package:x3_component_core/x3_component_core.dart';
import 'package:x3_business_core/business_customer/page/business_customer_details_behavior.dart';

class BusinessCustomerDetailsCircleProgress extends StatelessWidget {

  BusinessCustomerDetailsCircleProgress({Key key, @required this.vipId}) : super(key: key);

  final String vipId;

  @override
  Widget build(BuildContext context) {
    return BaseCardComponent(
      child: BaseScreenRefreshComponent(
        request: new BaseScreenRequestModel('/vip/customer/query/czdetail/{vipId}', method: BaseHttpMethodEnum.GET, params: {'vipId': vipId}),
        controller: new BaseFutureController(),
        builder: (BaseHttpResultModel result) => _buildMainScaffold(context, result.data),
      ),
    );
  }

  Widget _buildMainScaffold(BuildContext context, dynamic data) {
    return BaseScreenRefreshComponent(
      request: new BaseScreenRequestModel('/vip/customer/query/czdetail/{vipId}', method: BaseHttpMethodEnum.GET),
      controller: new BaseFutureController(),
      builder: (BaseHttpResultModel result) {
        List<BaseHttpResponseModel> responses = BaseTransformUtil.transformToListResponseData(result.data);
        return BaseInformationRow<BaseHttpResponseModel>(
          list: BaseTransformUtil.getShowResponseModels(responses),
          builder: (BaseHttpResponseModel response) {
            String numberText = BaseUtils.getKeyData(data, response.fieldName).toString();
            return GestureDetector(
              onTap: () {
                BaseRouterUtil().pushNamed(BusinessCustomerDetailsBehavior.sName, arguments: response);
              },
              child: BaseInformationRowItem(
                text: response.name,
                numberText: numberText.length == 0 ? '0' : numberText,
                decorator: (dynamic text) => _buildCircleProgress(context, text),
              ),
            );
          },
        );
      },
      serviceType: BaseScreenRefreshServiceType.Response,
    );
  }

  Widget _buildCircleProgress(BuildContext context, dynamic text) {
    return Container(
      height: 50,
      width: 50,
      alignment: Alignment.center,
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [Color.fromRGBO(250, 232, 101, 1), Color.fromRGBO(243, 207, 80, 1), Color.fromRGBO(237, 187, 92, 1)],
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
        ),
        shape: BoxShape.circle,
      ),
      child: RichText(
        text: TextSpan(style: Theme.of(context).textTheme.bodyText2, children: [TextSpan(text: text, style: TextStyle(fontSize: 15)), TextSpan(text: '天')]),
      ),
    );
  }
}
